package demo;

import java.lang.reflect.Array;

class MyArray<T> {

    /**
     * 通过反射创建，指定类型的数组
     * @param clazz
     * @param capacity
     */

    public T[] array;

    public MyArray() {
    }

    public MyArray(Class<T> clazz, int capacity) {
        array = (T[]) Array.newInstance(clazz, capacity);
    }

    public T getPos(int pos) {
        return this.array[pos];
    }
    public void setVal(int pos,T val) {
        this.array[pos] = val;
    }
    public T[] getArray() {
        return array;
    }
}

public class TestDemo {
    public static void main(String[] args) {
        MyArray<Integer> myArray1 = new MyArray();
        Integer[] array1 = myArray1.getArray();
    }
}
